package com.xingmei.springbootdemo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xingmei.springbootdemo.mapper.UserMapper;
import com.xingmei.springbootdemo.model.User;
import com.xingmei.springbootdemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Object saveUserWrapper(User user) {
        //Object proxy= AopContext.currentProxy();
        return saveUser(user);
    }

    @Override
    public Object saveUser(User user) {
        int c = userMapper.insert(user);
        if (user.getAge()%2 ==1) {
            throw new RuntimeException("奇数年龄异常");
        }
        return c;
    }

    @Override
    public List<User> selectByName(String name) {
        return userMapper.selectByName(name);
    }

}